package cn.fl.riskctrl.controller;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.riskctrl.service.IRskCtrlMDService;
import cn.fl.riskctrl.vo.RskCtrlDVO;
import cn.fl.riskctrl.vo.RskCtrlMVO;
import cn.fl.system.constant.SysLogConstant;
import fl.riskctrl.facade.riskctrl.condition.RskCtrlDQC;
import fl.riskctrl.facade.riskctrl.condition.RskCtrlMQC;

/**
 * Created by Administrator on 2017/6/5.
 */
@Controller
@RequestMapping("/riskctrl/rskctrlmd")
public class RskCtrlMDController {

	private static final Logger logger = LoggerFactory.getLogger(RskCtrlMDController.class);

    /**
     * 第三方征信风控管理主表信息服务
     */
    @Autowired
    private IRskCtrlMDService rskCtrlMDService;

    /**
     * 到征信风控管理主表信息主页面
     */
    @RequestMapping(value = "/toMainPage.do", method = { RequestMethod.GET })
    public ModelAndView toMainPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toList", "跳转到第三方征信风控管理主表信息页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView view = new ModelAndView("riskctrl/riskctrlmd/riskCtrlMDMain");
        return view;
    }

    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object initRiskMList(HttpServletRequest request, HttpServletResponse response) {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "initRiskMList", " 初始化列表.请求参数：" + CurrentThreadContext.getCurrentUserName());
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String compNm = request.getParameter("compNm");
        String compCd = request.getParameter("compCd");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(currentPage)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }
        RskCtrlMQC qc = new RskCtrlMQC();
        if (StringUtils.isNotEmpty(compNm)) {
            qc.setCompNm(compNm);
        }
        if (StringUtils.isNotEmpty(compCd)) {
            qc.setCompCd(compCd);
        }
        page.setCondition(qc);

        Pager pager = this.rskCtrlMDService.searchListPage(page);
        List<RskCtrlMVO> list = (List<RskCtrlMVO>) pager.getResultList();
        ListPageVO<RskCtrlMVO> listPage = new ListPageVO<RskCtrlMVO>(list, pager.getTotalCount());
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "initRiskMList", " 初始化列表.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return listPage;
    }

    /**
     * 初始化风控管理子表列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/ctrDInitList.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object initRiskDList(HttpServletRequest request, HttpServletResponse response) {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "initRiskDList", " 初始化风控管理子表列表.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        String compCd = request.getParameter("compCd");
        RskCtrlDQC qc = new RskCtrlDQC();
        if (StringUtils.isNotEmpty(compCd)) {
            qc.setCompCd(compCd);
        }
        List<RskCtrlDVO> list = this.rskCtrlMDService.searchListSon(qc);
        ListPageVO<RskCtrlDVO> listPage = new ListPageVO<RskCtrlDVO>(list, list.size());
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "initRiskDList", " 初始化风控管理子表列表.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return listPage;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object addM(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "addM", " 新增.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        RskCtrlMVO entity = new RskCtrlMVO();
        try {
            entity = this.getRequestParamForRskAdd(request);//获取参数
            Long id = this.rskCtrlMDService.add(entity);
            result.setData(id);
            BaseLogUtils.info(logger, "addM", "新增风控管理主表信息成功,ID:"+id+".DATA:"+ JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "addM", "新增风控管理主表信息失败.DATA:"+JSONObject.toJSONString(entity)+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "addM", "新增风控管理主表信息失败,系统错误.DATA:"+JSONObject.toJSONString(entity)+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "addM", " 新增.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 新增子表数据
     */
    @RequestMapping(value = "/addSON.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object addD(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "addD", " 新增风控管理子表信息.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        RskCtrlDVO entity = new RskCtrlDVO();
        try {
            entity = this.getRequestParamForRskSONAdd(request);//获取参数
            Long id = this.rskCtrlMDService.add(entity);
            result.setData(id);
            BaseLogUtils.info(logger, "addD", "新增风控管理子表信息成功,ID:"+id+".DATA:"+ JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "addD", "新增风控管理子表信息失败.DATA:"+JSONObject.toJSONString(entity)+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "addD", "新增风控管理子表信息失败,系统错误.DATA:"+JSONObject.toJSONString(entity)+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "addD", " 新增风控管理子表信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object modifyM(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifyM", " 修改风控管理主表信息.请求参数：" + CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
        RskCtrlMVO entity = new RskCtrlMVO();
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "modifyM", "修改风控管理主表信息,主键参数为空！.ID:"+id, CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            entity = this.getRequestParamForRskModify(request);
            entity.setId(Long.valueOf(id));
            boolean success = this.rskCtrlMDService.modify(entity);
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.info(logger, "modifyM", "修改风控管理主表信息失败.DATA:"+JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
            } else {
                BaseLogUtils.info(logger, "modifyM", "修改风控管理主表信息成功.DATA:"+JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
            }
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "modifyM", "修改风控管理主表信息失败.DATA:"+JSONObject.toJSONString(entity)+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "modifyM", "修改风控管理主表信息失败,系统错误.DATA:"+JSONObject.toJSONString(entity)+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifyM", " 修改风控管理主表信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/modifySON.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object modifyD(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifyD", " 修改风控管理子表信息.请求参数：" + CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
        RskCtrlDVO entity = new RskCtrlDVO();
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "modifyD", "修改风控管理子表信息,主键参数为空！.ID:"+id, CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            entity = this.getRequestParamForRskSONModify(request);
            entity.setId(Long.valueOf(id));
            boolean success = this.rskCtrlMDService.modify(entity);
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.info(logger, "modifyD", "修改风控管理子表信息失败.DATA:"+JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
            } else {
                BaseLogUtils.info(logger, "modifyD", "修改风控管理子表信息成功.DATA:"+JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
            }
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "modifyD", "修改风控管理子表信息失败.DATA:"+JSONObject.toJSONString(entity)+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "modifyD", "修改风控管理子表信息失败,系统错误.DATA:"+JSONObject.toJSONString(entity)+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifyD", " 修改风控管理子表信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 修改风控管理主表状态
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/modifySts.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object modifySts(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifySts", " 修改风控管理主表状态信息.请求参数：" + CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        String isValid = request.getParameter("isValid");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "modifySts", "修改风控管理主表状态信息,主键参数为空！", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            boolean success = this.rskCtrlMDService.modifyRMIsvalid(Long.valueOf(id), Integer.parseInt(isValid));
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "modifySts", "修改风控管理主表状态失败,ID:"+id, CurrentThreadContext.getCurrentUserName());
            } else {
                BaseLogUtils.info(logger, "modifySts", "修改风控管理主表状态成功,ID:"+id, CurrentThreadContext.getCurrentUserName());
            }
        }catch(BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "modifySts", "修改风控管理主表状态失败,ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch(Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "modifySts", "修改风控管理主表状态失败,系统错误.ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifySts", " 修改风控管理主表状态信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 修改风控管理子表状态
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/modifySONSts.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object modifySONSts(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifySONSts", " 修改风控管理子表状态信息.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        String isValid = request.getParameter("isValid");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "modifySONSts", "修改风控管理子表状态信息,主键参数为空！", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            boolean success = this.rskCtrlMDService.modifyRDIsvalid(Long.valueOf(id), Integer.parseInt(isValid));
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "modifySONSts", "修改风控管理子表状态失败,ID:"+id, CurrentThreadContext.getCurrentUserName());
            } else {
                BaseLogUtils.info(logger, "modifySONSts", "修改风控管理子表状态成功,ID:"+id, CurrentThreadContext.getCurrentUserName());
            }
        }catch(BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "modifySONSts", "修改风控管理子表状态失败,ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch(Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "modifySONSts", "修改风控管理子表状态失败,系统错误.ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifySONSts", " 修改风控管理子表状态信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 删除数据
     */
    @RequestMapping(value = "/removeById.do", method = {RequestMethod.GET })
    @ResponseBody
    public DataResultVO removeMById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "removeMById", " 删除风控管理主表信息.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "removeMById", "删除风控管理主表信息,主键参数为空！", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            boolean success = this.rskCtrlMDService.removeById(Long.valueOf(id));
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
                BaseLogUtils.info(logger, "removeMById", "删除风控管理主表信息失败,ID:"+id, CurrentThreadContext.getCurrentUserName());
            } else {
                BaseLogUtils.info(logger, "removeMById", "删除风控管理主表信息成功,ID:"+id, CurrentThreadContext.getCurrentUserName());
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "removeMById", "删除风控管理主表信息失败,ID:"+id+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "removeMById", "删除风控管理主表信息失败,系统错误.ID:"+id+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "removeMById", " 删除风控管理主表信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 删除数据
     */
    @RequestMapping(value = "/removeSONById.do", method = {RequestMethod.GET })
    @ResponseBody
    public DataResultVO removeDById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "removeDById", " 删除风控管理子表信息.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "removeDById", "删除风控管理子表信息,主键参数为空！", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            boolean success = this.rskCtrlMDService.removeSONById(Long.valueOf(id));
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
                BaseLogUtils.info(logger, "removeDById", "删除风控管理子表信息失败,ID:"+id, CurrentThreadContext.getCurrentUserName());
            } else {
                BaseLogUtils.info(logger, "removeDById", "删除风控管理子表信息成功,ID:"+id, CurrentThreadContext.getCurrentUserName());
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "removeDById", "删除风控管理子表信息失败,ID:"+id+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "removeDById", "删除风控管理子表信息失败,系统错误.ID:"+id+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "removeDById", " 删除风控管理子表信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 得到一条记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object getMById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "getMById", " 获取风控管理主表信息.请求参数：" + CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "getMById", "获取风控管理主表信息,主键参数为空！", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        try {
            RskCtrlMVO vo = this.rskCtrlMDService.selectById(Long.valueOf(id));
            if(null == vo){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "getMById", "获取风控管理主表信息不存在,ID:"+id, CurrentThreadContext.getCurrentUserName());
            } else {
                result.setData(vo);
                BaseLogUtils.info(logger, "getMById", "获取风控管理主表信息成功,ID:"+id, CurrentThreadContext.getCurrentUserName());
            }
        }catch(BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "getMById", "获取风控管理主表信息失败,ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch(Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "getMById", "获取风控管理主表信息失败,系统错误.ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "getMById", " 获取风控管理主表信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 得到一条记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getSONById.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object getDById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "getDById", " 获取风控管理主表信息.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "getDById", "获取风控管理主表信息,主键参数为空！", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        try {
            RskCtrlDVO vo = this.rskCtrlMDService.selectSONById(Long.valueOf(id));
            if(null == vo){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "getDById", "获取风控管理主表信息不存在,ID:"+id, CurrentThreadContext.getCurrentUserName());
            }
            result.setData(vo);
            BaseLogUtils.info(logger, "getDById", "获取风控管理主表信息成功,ID:"+id, CurrentThreadContext.getCurrentUserName());
        }catch(BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "getDById", "获取风控管理主表信息失败,ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch(Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "getDById", "获取风控管理主表信息失败,系统错误.ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "getDById", " 获取风控管理主表信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 获取征信请求参数(新增)
     * @param request 请求
     * @return
     */
    private RskCtrlMVO getRequestParamForRskAdd(HttpServletRequest request)throws BaseException{
        RskCtrlMVO rskCtrlMVO = this.getRequestParamForRsk(request);
        rskCtrlMVO.setCrtTm(new Date());
        rskCtrlMVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        return rskCtrlMVO;
    }

    /**
     * 获取征信接口请求参数(新增)
     * @param request 请求
     * @return
     */
    private RskCtrlDVO getRequestParamForRskSONAdd(HttpServletRequest request)throws BaseException{
        RskCtrlDVO rskCtrlDVO = this.getRequestParamForRskSON(request);
        rskCtrlDVO.setCrtTm(new Date());
        rskCtrlDVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        return rskCtrlDVO;
    }

    /**
     * 获取征信请求参数(修改)
     * @param request 请求
     * @return
     */
    private RskCtrlMVO getRequestParamForRskModify(HttpServletRequest request)throws BaseException{
        RskCtrlMVO rskCtrlMVO = this.getRequestParamForRsk(request);
        rskCtrlMVO.setMdfTm(new Date());
        rskCtrlMVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
        return rskCtrlMVO;
    }

    /**
     * 获取征信接口请求参数(修改)
     * @param request 请求
     * @return
     */
    private RskCtrlDVO getRequestParamForRskSONModify(HttpServletRequest request)throws BaseException{
        RskCtrlDVO rskCtrlDVO = this.getRequestParamForRskSON(request);
        rskCtrlDVO.setMdfTm(new Date());
        rskCtrlDVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
        return rskCtrlDVO;
    }

    /**
     * 获取银行参数信息
     * @param request
     * @return
     * @throws BaseException
     */
    private RskCtrlMVO getRequestParamForRsk(HttpServletRequest request)throws BaseException{
        String compNm = request.getParameter("compNm");//公司名称
        String compCd = request.getParameter("compCd");//公司编码
        String reqProtocol = request.getParameter("reqProtocol");//请求协议
        String sysDesc = request.getParameter("sysDesc");//描述
        String isValid = request.getParameter("isValid");//是否启用

        RskCtrlMVO rskCtrlMVO = new RskCtrlMVO();
        rskCtrlMVO.setCompNm(compNm.trim());
        rskCtrlMVO.setCompCd(compCd.trim());
        rskCtrlMVO.setReqProtocol(reqProtocol.trim());
        rskCtrlMVO.setSysDesc(sysDesc.trim());
        rskCtrlMVO.setIsValid(Integer.parseInt(isValid));
        return rskCtrlMVO;
    }

    /**
     * 获取银行参数信息
     * @param request
     * @return
     * @throws BaseException
     */
    private RskCtrlDVO getRequestParamForRskSON(HttpServletRequest request)throws BaseException{
        String infNm = request.getParameter("infNm");//接口名称
        String compCd = request.getParameter("compCd");//公司编码
        String reqMtdCd = request.getParameter("reqMtdCd");//接口编码
        String dataFm = request.getParameter("dataFm");//数据格式
        String codeFm = request.getParameter("codeFm");//编码格式
        String reqUrl = request.getParameter("reqUrl");//请求地址
        String accountNm = request.getParameter("accountNm");//账号
        String accountPwd = request.getParameter("accountPwd");//密码
        String accountPwd2 = request.getParameter("accountPwd2");//密码
        String connectTimeout = request.getParameter("connectTimeout");//连接超时时间
        String socketTimeout = request.getParameter("socketTimeout");//获取数据超时时间
        String infDesc = request.getParameter("infDesc");//描述
        String isValid = request.getParameter("isValid");//是否启用

        RskCtrlDVO rskCtrlDVO = new RskCtrlDVO();
        rskCtrlDVO.setInfNm(infNm.trim());
        rskCtrlDVO.setCompCd(compCd.trim());
        rskCtrlDVO.setReqMtdCd(reqMtdCd.trim());
        rskCtrlDVO.setDataFm(dataFm.trim());
        rskCtrlDVO.setCodeFm(codeFm.trim());
        rskCtrlDVO.setReqUrl(reqUrl.trim());
        rskCtrlDVO.setAccountNm(accountNm.trim());
        rskCtrlDVO.setAccountPwd(accountPwd.trim());
        rskCtrlDVO.setAccountPwd2(accountPwd2.trim());
        rskCtrlDVO.setIsValid(Integer.parseInt(isValid));
        if (StringUtils.isNotEmpty(connectTimeout)) {
            rskCtrlDVO.setConnectTimeout(Long.parseLong(connectTimeout));
        } else {
            rskCtrlDVO.setConnectTimeout(5000l);
        }
        if (StringUtils.isNotEmpty(socketTimeout)) {
            rskCtrlDVO.setSocketTimeout(Long.parseLong(socketTimeout));
        } else {
            rskCtrlDVO.setSocketTimeout(5000l);
        }
        rskCtrlDVO.setInfDesc(infDesc.trim());
        return rskCtrlDVO;
    }
}
